package thread.demo02;


public class GuiTuSaiPaoLianXi implements Runnable {
    private static String winner;

    @Override
    public void run() {
        for (int i = 1; i <= 1000; i++) {

            if (Thread.currentThread().getName().equals("憨憨")&& i==500){
                break;
            }
            boolean b = gameOver(i);
            if (b){
             break;
            }
            System.out.println(Thread.currentThread().getName() + "-->跑了" + i + "步");

        }


    }


    boolean gameOver(int b) {

        if (winner != null) {
            return true;
        }
        if (b >= 1000) {
            winner = Thread.currentThread().getName();
            System.out.println("胜利者是" + winner);
            return true;
        }
        return false;
    }

    public static void main(String[] args) {
        GuiTuSaiPaoLianXi guiTuSaiPaoLianXi = new GuiTuSaiPaoLianXi();
        new Thread(guiTuSaiPaoLianXi,"憨憨").start();
        new Thread(guiTuSaiPaoLianXi,"憨批").start();
    }
}
